Skip to content

update AdvancedTlsX509KeyManager to support key alias for reloaded cert#12686

Open
zhangweikop wants to merge 1 commit intogrpc:masterfrom
zhangweikop:tls-key-manager-update
Open

update AdvancedTlsX509KeyManager to support key alias for reloaded cert#12686
zhangweikop wants to merge 1 commit intogrpc:masterfrom
zhangweikop:tls-key-manager-update

Conversation

@zhangweikop
Copy link

Overview

Make the alias in AdvancedTlsX509KeyManager dynamic so it can be used with Netty's
OpenSslCachingX509KeyManagerFactory to update key material after reload.

Fixes #12670

Problem

When using SslProvider.OPENSSL, each TLS handshake must encode Java key material into a native
buffer consumed by OpenSSL, which can account for ~8% of server CPU. Netty's
OpenSslCachingX509KeyManagerFactory avoids this by caching the encoded buffer keyed by alias —
but the previous implementation always returned "default", so the factory could never detect
credential rotations and create a new cache entry on cert reload.

Details

  • The alias is now set to key-<N> (e.g. key-1, key-2, ...) and incremented on every
    updateIdentityCredentials call, ensuring the same alias always maps to the same key material.
  • A new constructor AdvancedTlsX509KeyManager(int revisionWarningThreshold) allows customizing
    the soft warning threshold (default: 1024, matching OpenSslCachingX509KeyManagerFactory's
    default maxCachedEntries). A warning is logged when the counter reaches the threshold, since
    beyond that point new aliases won't be cached and per-handshake encoding overhead resumes. The
    key manager remains fully functional past this threshold.
  • All alias methods return null before any credentials are loaded.
  • Recommended usage with OpenSSL:
new OpenSslCachingX509KeyManagerFactory(
    new KeyManagerFactoryWrapper(advancedTlsKeyManager))

@zhangweikop zhangweikop force-pushed the tls-key-manager-update branch from a54cf0b to a18d1a6 Compare March 10, 2026 21:38
@zhangweikop zhangweikop force-pushed the tls-key-manager-update branch from a18d1a6 to 9456de4 Compare March 10, 2026 22:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Performance overhead on handshake when using AdvancedTlsX509KeyManager with OPENSSL provider

1 participant